import { BaseMod } from "../base/BaseMod";
import { BaseTimer } from "../base/BaseTimer";
import { debugMgr } from "./DebugMgr";
import { MapMod } from "../mod/map/MapMod";
import { PlayerMod } from "../mod/player/PlayerMod";

/**
 * 模块管理
 */
export const modMgr = _ as ModMgr;
export class ModMgr extends BaseTimer {

    /** 所有模块 */
    mods: BaseMod[];
    /** 游戏模块 */
    gameMods: BaseMod[];

    init() {
        (modMgr as any) = this;
        this.mods = [];
        BaseMod.init();
    }

    /**
     * 初始化单个模块
     * @param mod 
     */
    initMod(mod: BaseMod) {
        if (mod.isInited) return;
        mod.init();
        this.mods.push(mod);
        debugMgr.moduleGlobal();
    }

    /**
     * 初始化的所有游戏模块
     */
    initGameMods(onProg?: (loaded: number, total: number) => any) {
        this.gameMods = [
            new MapMod(),
            new PlayerMod()
        ];
        let loaded = 0;
        let total = this.gameMods.length;
        for (let mod of this.gameMods) {
            this.initMod(mod);
            onProg && onProg(++loaded, total);
        }
    }

}